{extend name="public:base" /}

{block name="title"}后台登录{/block}

{block name="body"}
<style>
    input {
        height: 42px;
    }

    .login-box {
        padding-top: 15%;
    }

    .gray-bg {
        background: url('__ADMIN__/img/bg.jpg');
    }
</style>

<body class="gray-bg">

<div class="middle-box text-center loginscreen animated fadeInDown login-box">
    <h3 style="color: #FFFFFF">欢迎登录{:C('WEB_TITLE')}后台管理</h3>
    <form class="m-t" role="form" method="post" action="/admin/login/login.json">
        <div class="form-group">
            <input type="text" name="account" autocomplete="off" class="form-control"
                   placeholder="账号">
        </div>
        <div class="form-group">
            <input type="password" name="password" class="form-control" placeholder="密码">
        </div>
        <!--<div class="form-group">
            <input type="text" class="form-control" name="code" placeholder="验证码"
                   style="float: left; width: 150px; height: 40px;">
            <img src="{:captcha_src()}" onclick="this.src='{:captcha_src()}'">
        </div>-->

        {:token()}
        <button type="button" class="btn btn-primary block full-width m-b ajax-post">登录</button>
    </form>
</div>

<script src="__ADMIN__/js/jquery-3.1.1.min.js"></script>
<script src="__ADMIN__/js/popper.min.js"></script>
<script src="__ADMIN__/js/bootstrap.js"></script>
<script src="__POPUP__/popup.js"></script>
</body>

{/block}
{block name="company"}
{include file="Public:company_select" /}
{/block}
{block name="js"}
<script type="text/javascript">
    console.log("sssss")
    $(document).ready(function () {
        console.log("sssssssss");
        $('.login-ajax-post').click(function () {
            console.log("sss");
            __submitAjaxForm($(this).parents('form'));
        });
        function open_company(){
             $('#__COMPANY_DIALOG').modal('show');
            getCompany(1);
        }
        function getCompany(options) {
            let url = "{:url('admin/company/dialogCompany')}";
            if (typeof options === 'object') {
                if (options.url) {
                    url = options.url;
                } else {
                    url = url + '?' + $.param(options);
                }
            } else {
                url = url + '?page=' + options;
            }
            $.get(url, function (data, status) {
				if(data.data==''){
					alert(data.msg);return false;
				}
                $('#__COMPANY_DIALOG_BODY').html(data);
                btnBindEvent();
            })
        }


        function btnBindEvent() {
            $(".company-table-list").on("click", ".company-choice", function (e) {
                let dataId = $(e.currentTarget).data("id");
                $.ajax({
                    url: "{:url('/admin/company/updateCompany')}?companyId=" + dataId,
                    type: "get",
                    success: function (data) {
                        console.log(data);
                        if (data.code === 1) {
                            $('#__COMPANY_DIALOG').modal('hide');
                            window.location.reload();
                        } else {
                            layer.msg(data.msg, {icon: 2, time: 2000});
                        }
                    },
                    error: function (data) {
                        // layer.msg(data.msg, {icon: 2, time: 2000});
                        console.log(data);
                    }
                });
            });
            $(".__company_global_data_list__").on("click", "a", function (e) {
                e.preventDefault();
                const options = {};
                options['url'] = $(this).attr('href');
                getCompany(options);
            });
        }
    
    function __submitAjaxForm($form) {
        //加载层
        // var index = layer.load(0, {shade: [0.2, '#000']});
        var index = layer.load(0, {shade: false});
        var action = $form.attr("action");
        if (!action) {
            var url = window.location.href;
        } else {
            //取出第一个字符
            var first = action.slice(0, 1);
            if (first == '/') {
                var url = action;
            } else {
                var url = '/' + action
            }
        }
        var formData = $form.serialize();
        $.post(url, formData, function (res, status, xhr) {
            if (res.code === 1) {
                toast.success(res.msg, {duration: (res.wait || 3) * 1000}).then(() => {
                    layer.close(index);
                    open_company();
                });
            } else {
                layer.close(index);
                toast.error(res.msg, {duration: (res.wait || 3) * 1000}).then(() => {
                    if (xhr.getResponseHeader('__token__')) {
                        $("[name='__token__']").val(xhr.getResponseHeader('__token__'));
                    }
                });
            }
        }, 'json');

        setTimeout(function () {
            layer.close(index);
        }, 3000)
        return false;
    }
})
</script>
{/block}